<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script language="javascript">
    var xmlhttp;
    function init() {
       // put more code here in case you are concerned about browsers that do not provide XMLHttpRequest object directly
       xmlhttp = new XMLHttpRequest();
    }

    function readLocal(){

        if (window.localStorage) {
            //Get the seller object
            var seller = localStorage.getItem("seller");
            seller = JSON.parse(seller);
            document.getElementById("lastName").value = seller.lastName;
            document.getElementById("firstName").value = seller.firstName;
            document.getElementById("sellerid").value = seller.id;
        }
    }


    function seveLocal() {
        var sellerid = document.getElementById("sellerid");
        var url = "http://localhost:8080/AuctionApp/resources/sellers/"+sellerid.value;
        xmlhttp.open('GET',url,true);
        xmlhttp.send(null);

        xmlhttp.onreadystatechange = function() {

               if (xmlhttp.readyState == 4) {
                  if ( xmlhttp.status == 200) {

                    var seller = eval( "(" +  xmlhttp.responseText + ")");
                    if (window.localStorage) {
                        localStorage.setItem("seller",JSON.stringify(seller));
                        alert("The information of the Seller #" + sellerid.value +  " has been stored successfully.");
                    } else {
                        alert("Your Browser does not support LocalStorage.");
                    }
                 }
                 else
                       alert("Error!!! ->" + xmlhttp.responseText);
              }
        };
    }
  </script>
  </head>
  <body  onload="init()">
   <h1>Call Seller RESTful Web Service </h1>
   <table>
   <tr>
       <td>Enter Seller ID :  </td>
       <td><input type="text" id="sellerid" size="10"/>  
       <input type="button" value="Load seller in local browser " onclick="seveLocal()"/></td>
   </tr>

    <tr>
       <td colspan="2">-----------------------------------------------------  </td>
   </tr>
   <tr>
       <td>Display from local  :  </td>
       <td><input type="button" value="Read Values" onclick="readLocal()"/></td>
   </tr>

   <tr>
       <td>First Name :  </td>
       <td><input type="text" readonly="true" id="firstName" size="20"/> </td>
   </tr>

   <tr>
       <td>Last Name :  </td>
       <td><input type="text" readonly="true" id="lastName" size="20"/> </td>
   </tr>
   </table>
  </body>
</html>